﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace NuaTarDoneng
{
    /// <summary>
    /// PostMan 的摘要说明
    /// </summary>
    public class PostMan : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request.QueryString["action"];
            string did = context.Request.Params["did"];
            string info = context.Request.Params["info"];
            string result = "";
            if (action == "PostSug") {
                
                result = SugLog(did, info);
            }
            else if (action == "PostEr") {
                string softid = context.Request.Params["softid"];
                result = SoftLog(did, softid, info);
            }
            context.Response.Write(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        public string SugLog(string devieceid,string info)
        {
            string logid = Guid.NewGuid().ToString("N");
            string time = DateTime.Now.ToString("yyyyMMddHHmmss");
            string cmdtext = "insert into SugInfo values('" + logid + "','" + devieceid + "','" + info + "'," + time + ",0)";
            string result = "";
            SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["constr"]);
            SqlCommand cmd = cnn.CreateCommand();
            cmd.CommandText = cmdtext;
            cnn.Open();
            int i = (int)cmd.ExecuteNonQuery();
            if (i == 1)
            {
                result = "OK";
            }
            else
            {
                result = "ER";

            }
            cnn.Close();
            return result;
        }
        public string SoftLog(string devieceid,string softid, string info)
        {
            string logid = Guid.NewGuid().ToString("N");
            string time = DateTime.Now.ToString("yyyyMMddHHmmss");
            string cmdtext = "insert into SoftLog values('" + logid + "','" + devieceid + "','" + softid + "'," + time + ",'" + info + "')";
            string result = "";
            SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["constr"]);
            SqlCommand cmd = cnn.CreateCommand();
            cmd.CommandText = cmdtext;
            cnn.Open();
            int i = (int)cmd.ExecuteNonQuery();
            if (i == 1)
            {
                result = "OK";
            }
            else
            {
                result = "ER";

            }
            cnn.Close();
            return result;
        }

    }
}